﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.PhotoRindGrid;
using MINERP.BLL.InnerReturn;
using MINERP.MODEL.FoundationModel;
using PhotoView=MINERP.BLL.InnerReturn.PhotoView;


namespace MINERP.PhotoRindGrid.Forms
{
    public partial class FrmFanDan : Form
    {
        public FrmFanDan(List<PhotoInfo_Info> inList, int inUserId, int inCurrTech)
        {
            InitializeComponent();
            listPhotoView=new List<PhotoView>();
            foreach (PhotoInfo_Info list in inList)
            {
                string aaa = "";
                listPhotoView.Add(_bll.GetPhotoViewByBarCode(list.PhotoBarCode,out aaa));
            }
            UserId = inUserId;
            CurrTechId = inCurrTech;

        }
        private List<MINERP.BLL.InnerReturn.PhotoView> listPhotoView;
        private int UserId;
        private int CurrTechId;
        
        private int FanDaoTechId = 0;
        private int FanDaoUsserId = 0;

        private InnerReturnBLL2 _bll = new InnerReturnBLL2();



        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            //this.Close();
        }

        private void simpleButtonOK_Click(object sender, EventArgs e)
        {
            try
            {
                if(FanDaoUsserId==0)
                {
                    MessageBox.Show("请选择责任人", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if(FanDaoTechId==0)
                {
                    MessageBox.Show("请选择返单流程", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                List<MINERP.BLL.InnerReturn.PhotoView> rtnList = _bll.CreateInnerReturn(listPhotoView,FanDaoUsserId, UserId,
                                                                                        this.richTextBoxRemark.Text.Trim
                                                                                            (),FanDaoTechId );
                if (rtnList.Count() == 0)
                {
                    MessageBox.Show("返工单创建成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.OK;
                    //this.Close();
                }
                else
                {
                    MessageBox.Show("返工单创建失败，请检查产品流程和返单流程", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.Cancel;
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接数据库失败，请稍后重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.Cancel;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

        }

        private void FrmFanDan_Load(object sender, EventArgs e)
        {
            comboBoxErrUser.DataSource = _bll.GetAllUsers();
            comboBoxErrUser.DisplayMember = "UserName";
            comboBoxErrUser.ValueMember = "UserID";
            comboBoxErrFlow.DataSource = _bll.GetAllTech();
            comboBoxErrFlow.DisplayMember = "TechName";
            comboBoxErrFlow.ValueMember = "TechId";
        }

        private void comboBoxErrFlow_DropDownClosed(object sender, EventArgs e)
        {
            this.FanDaoTechId = ((Tb_Tech_Info)comboBoxErrFlow.SelectedItem).TechId;

        }

        private void comboBoxErrUser_DropDownClosed(object sender, EventArgs e)
        {
            FanDaoUsserId = ((User_Info) comboBoxErrUser.SelectedItem).UserID;
        }

    }

}

